package com.bjwl.service.impl;

import com.bjwl.dao.CardDenominationMapper;
import com.bjwl.pojo.CardDenomination;
import com.bjwl.pojo.vo.BasicQueryVo;
import com.bjwl.service.CardDenominationService;
import com.bjwl.utils.Log4jUtils;
import com.bjwl.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: dzx
 * @Date:Create：in 2020/5/8 14:03
 * @Description:
 * @Modified By：
 * @Version: 1.0
 */
@Service
public class CardDenominationServiceImpl implements CardDenominationService {

    @Autowired
    private CardDenominationMapper cardDenominationMapper;



    @Override
    public boolean addCardDenomination(CardDenomination cardDenomination) {

            cardDenominationMapper.addCardDenomination(cardDenomination);
            return true;

    }

    @Override
    public PageBean<CardDenomination> findAllCardDenomination(BasicQueryVo vo) {
        PageBean<CardDenomination> pageBean = new PageBean<CardDenomination>(vo.getPageNum(),10,cardDenominationMapper.getTotalRecord(vo));
        pageBean.setData(cardDenominationMapper.findAllCardDenomination(pageBean,vo));
        return pageBean;
    }


    @Override
    public CardDenomination editStart(Integer id) {
        return cardDenominationMapper.findCardDenominationById(id);
    }

    @Override
    public boolean updateCardDenomination(CardDenomination cardDenomination) {
        CardDenomination CardDenomination1 = cardDenominationMapper.findCardDenominationBy(cardDenomination.getDenomination());
        if(CardDenomination1 == null){
            Integer state = cardDenominationMapper.updateCardDenomination(cardDenomination);
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteCardDenomination(Integer id) {
        try {
            cardDenominationMapper.deleteCardDenomination(id);
        }catch (Exception e){
            Log4jUtils.LITERAL3.getLog().error(e.getMessage());
        }
        return true;
    }

    @Override
    public List<CardDenomination> findAll() {
        List<CardDenomination> list  = cardDenominationMapper.findAll();
        return list;
    }

}
